/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hessingerbg.codebehind;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author MikeLaptop
 */
public class spell implements Serializable, Comparable {

    

    private String Name = "New Spell";
    private int Cooldown = 0;
    private int Usage = 0;
    private long lastuse = 0;
    private int keybind;
    private int keymod;
    private boolean force;
    private double castingtime = 0;
    private boolean requirescasting = false;
    private boolean hostile = false;

    public int getTogglefriendly() {
        return togglefriendly;
    }

    public void setTogglefriendly(int togglefriendly) {
        this.togglefriendly = togglefriendly;
    }

    public int getTogglehostile() {
        return togglehostile;
    }

    public void setTogglehostile(int togglehostile) {
        this.togglehostile = togglehostile;
    }

    private int togglehostile = 0;
    private int togglefriendly = 0;

    public boolean isFriendly() {
        return friendly;
    }

    public void setFriendly(boolean friendly) {
        this.friendly = friendly;
    }

    public boolean isHostile() {
        return hostile;
    }

    public void setHostile(boolean hostile) {
        this.hostile = hostile;
    }
    private boolean friendly = false;


    public boolean isRequirescasting() {
        return requirescasting;
    }

    public void setRequirescasting(boolean requirescasting) {
        this.requirescasting = requirescasting;
    }


    public double getCastingtime() {
        return castingtime;
    }

    public void setCastingtime(double castingtime) {
        this.castingtime = castingtime;
    }

    public int getCooldown() {
        return Cooldown;
    }

    public void setCooldown(int Cooldown) {
        this.Cooldown = Cooldown;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public int getUsage() {
        return Usage;
    }

    public void setUsage(int Usage) {
        this.Usage = Usage;
    }

    public int getKeybind() {
        return keybind;
    }

    public void setKeybind(int keybind) {
        this.keybind = keybind;
    }

    public long getLastuse() {
        return lastuse;
    }

    @Deprecated
    /**
     * As of 1.00a
     * should only be set by useSpell()
     */
    public void setLastuse(long lastuse) {
        this.lastuse = lastuse;
    }

    public boolean isValid()
    {
        return isactive && Name != null && Cooldown != -1 && Usage != -1;
    }

    public boolean isIsactive() {
        return isactive;
    }

    public void setIsactive(boolean isactive) {
        this.isactive = isactive;
    }


    public boolean isForce() {
        return force;
    }

    public void setForce(boolean force) {
        this.force = force;
    }

    public int getKeymod() {
        return keymod;
    }

    public void setKeymod(int keymod) {
        this.keymod = keymod;
    }
    private boolean isactive;

    @Override
    public String toString()
    {
       return Name;
    }

    public int compareTo(Object o) {
        return (this.Usage - ((spell)(o)).getUsage());
    }

    public boolean isNotOnCD() {
        return ((lastuse - System.currentTimeMillis()) < -this.Cooldown*1000);
    }

    public void useSpell(keyevent robot)
    {
        if(this.friendly)
            robot.pressKey(this.togglefriendly);
        if(this.hostile)
            robot.pressKey(this.togglehostile);

        if(keymod != -1)
            robot.pressKey(keymod);
        robot.pressKey(keybind);
        lastuse = System.currentTimeMillis();
        if(keymod != -1)
            robot.keyRelease(keymod);
        robot.keyRelease(keybind);
        
        try {
            Thread.sleep((long) castingtime * 1000);
        } catch (InterruptedException ex) {
            Logger.getLogger(spell.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


}
